package com.innovation.sys.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.innovation.sys.dao.SSysLogMapper;
import com.innovation.sys.pojo.SSysLog;
import com.innovation.sys.service.LogAdminService;

@Service
public class LogAdminServiceImpl implements LogAdminService {

	@Resource
	private SSysLogMapper logMapper;

	@Override
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public int addLog(SSysLog log) {
		return logMapper.insert(log);
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public List<SSysLog> findAllExplicitly() {
		return logMapper.selectAll();
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public PageInfo<Map<String, Object>> selectByOption(Map map, Integer pageNum, Integer pageSize) {
		int pageNo = pageNum == null ? 1 : pageNum;
		int pageSiz = pageSize == null ? 10 : pageSize;
		PageHelper.startPage(pageNo, pageSiz);
		List<Map<String, Object>> pList = logMapper.findAll(map);
		PageInfo<Map<String, Object>> page = new PageInfo<Map<String, Object>>(pList);
		return page;
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
	public List<SSysLog> queryByCriteria() {
		return logMapper.findByCriteria();
	}

}
